<?php

namespace plugin\laoha\app\admin\controller;

use plugin\laoha\app\model\Attach;
use support\exception\BusinessException;
use support\Request;
use support\Response;

/**
 * 附件管理 
 */
class AttachController extends CrudController
{
    protected $noNeedAuth = ['select', 'list', 'show', 'image', 'file', 'check'];
    protected $dataLimitField = 'user_id';

    public function __construct()
    {
        $this->model = new Attach;
        $this->rules = $this->getRules();
    }

    /**
     * 浏览
     * @return Response
     */
    protected function init()
    {
        $rules = $this->getAccess();
        $rules = $this->rules;
        return ['rules' => $rules, 'admin_id' => admin_id(), 'root' => 'attach'];
    }

    /**
     * 浏览
     * @return Response
     */
    public function index()
    {
        return view('attach/index', ['params' => $this->init()]);
    }


    /**
     * 列表
     * @return Response
     */
    public function list(Request $request)
    {
        $this->set = ['page_type' => 1, 'order_by' => '-id', 'data_format' => 'list', 'with' => ''];
        $this->builder = $this->model->with(['user:id,nickname'])->withCount('urls');
        return parent::list($request);
    }


}
